﻿namespace Storm.Docking.Visual.Drawing
{
	using System;
    using System.Collections;
	using System.Collections.Generic;
	using System.ComponentModel;
	using System.Data;
	using System.Drawing;
	using System.Drawing.Drawing2D;
	using System.Drawing.Imaging;
	using System.Text;
	using System.Windows.Forms;

	/// <summary>
	/// Represents an image with a transparent background.
	/// </summary>
	[ToolboxItem(false)]
	public class TransImage
        : Panel
    {
        #region Properties

        /// <summary>
        /// Gets or sets the image of the TransImage.
        /// </summary>
        public Image Image
		{
			get { return this.BackgroundImage; }
			set
			{
                if (value != null)
                {
                    Bitmap bitmap = new Bitmap(value);
                    bitmap.MakeTransparent();

                    this.BackgroundImage = bitmap;
                    Size = bitmap.Size;
                }
			}
        }

        #endregion

		/// <summary>
		/// Initializes a new instance of the <see cref="TransImage"/> class.
		/// </summary>
		/// <param name="image">The image.</param>
		public TransImage(Image image)
		{
            // Set styles to enable transparent background
			this.SetStyle(ControlStyles.Selectable, false);
			this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

			this.BackColor = Color.Transparent;
			this.Image = image;
		}
	}
}
